package com.example.maxboxtwo.components.function.Gradienter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.maxboxtwo.R;


public class GradienterView extends View {
    public Bitmap background;
    public Bitmap bubble;
    private Paint paint;
    private int xPosition,yPosition;

    private int getxPosition() {
        return xPosition;
    }

    public void setxPosition(int xPosition) {
        this.xPosition = xPosition;
    }

    private int getyPosition() {
        return yPosition;
    }

    public void setyPosition(int yPosition) {
        this.yPosition = yPosition;
    }

    public GradienterView(Context context) {
        super(context);
    }

    public GradienterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(background,0,0,paint);
        canvas.drawBitmap(bubble,getxPosition(),getyPosition(),paint);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if(w!=oldw||h!=oldh) {
            background = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.tools_level_bg_circle_all), w,h, true);
            bubble = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.tools_level_icon_circle), 100, 100, false);
            paint = new Paint();
            paint.setStyle(Paint.Style.STROKE);
            paint.setDither(true);
            paint.setAntiAlias(true);
            setxPosition((background.getWidth()-bubble.getWidth())/2);
            setyPosition((background.getHeight()-bubble.getHeight())/2);
        }
    }
}
